package com.publiccms.common.tools;

import java.util.Map;

import com.publiccms.common.view.MultiSiteImportDirective;
import com.publiccms.common.view.MultiSiteIncludeDirective;
import com.sanluan.common.base.Base;

public class SiteUtils extends Base {
    public static final String SITE_PATH_PREFIX = "/site_";
    public static final String CONTEXT_SITE_ID = "_siteId";
    public static final String CONTEXT_INCLUDE = "include";
    public static final String CONTEXT_IMPORT = "import";

    /**
     * @param path
     * @return
     */
    public static String getFullFileName(int siteId, String path) {
        path = path.replace("..", "");
        if (path.startsWith(SEPARATOR) || path.startsWith("\\")) {
            return SITE_PATH_PREFIX + siteId + path;
        }
        return SITE_PATH_PREFIX + siteId + SEPARATOR + path;
    }

    public static void expose(Map<String, Object> map, int siteId) {
        map.put(CONTEXT_SITE_ID, siteId);
        map.put(CONTEXT_INCLUDE, new MultiSiteIncludeDirective(siteId));
        map.put(CONTEXT_IMPORT, new MultiSiteImportDirective(siteId));
    }
}
